'use strict';
/* Controller for adding a new entry*/

blogApp.controller('addCommentCtrl',['$scope', '$http','$state',
    function($scope, $http,$state) {

        $scope.submit = function() {

            var comment = {};

            comment.author = this.author;
            comment.content = this.content;
            comment.entry = this.entry;
            console.log("Submitting");

            var data = angular.toJson(comment);
            $http({
                    url: 'comments/addComment',
                    method: "POST",
                    data: data,
                    headers: {'Content-Type': 'application/json'}
            }).success(function() {
                    console.log("Comment added");
                    console.log(comment);
                    $state.go('list', null, {reload:true});
                });
        };
    }
]);